
package gui;

import business.Cliente;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import vo.ClienteVO;

public class Cliente_Pesquisar extends javax.swing.JFrame {

    
    public Cliente_Pesquisar() {
        initComponents();
        updateClientes();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButtonClientePesquisarRG = new javax.swing.JRadioButton();
        jRadioButtonClientePesquisarNome = new javax.swing.JRadioButton();
        jTextFieldClientePesquisarBusca = new javax.swing.JTextField();
        jRadioButtonClientePesquisarCPF = new javax.swing.JRadioButton();
        jRadioButtonClientePesquisarCNH = new javax.swing.JRadioButton();
        jButtonClientePesquisarSelecionar = new javax.swing.JButton();
        jLabelClientePesquisarBusca = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableClientePesquisarTabela = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("gui/Bundle"); // NOI18N
        jRadioButtonClientePesquisarRG.setText(bundle.getString("Cliente_Pesquisar.jRadioButtonClientePesquisarRG.text")); // NOI18N

        jRadioButtonClientePesquisarNome.setText(bundle.getString("Cliente_Pesquisar.jRadioButtonClientePesquisarNome.text")); // NOI18N

        jRadioButtonClientePesquisarCPF.setText(bundle.getString("Cliente_Pesquisar.jRadioButtonClientePesquisarCPF.text")); // NOI18N

        jRadioButtonClientePesquisarCNH.setText(bundle.getString("Cliente_Pesquisar.jRadioButtonClientePesquisarCNH.text")); // NOI18N

        jButtonClientePesquisarSelecionar.setText(bundle.getString("Cliente_Pesquisar.jButtonClientePesquisarSelecionar.text")); // NOI18N
        jButtonClientePesquisarSelecionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClientePesquisarSelecionarActionPerformed(evt);
            }
        });

        jLabelClientePesquisarBusca.setText(bundle.getString("Cliente_Pesquisar.jLabelClientePesquisarBusca.text")); // NOI18N

        jTableClientePesquisarTabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "CPF", "RG", "CNH"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableClientePesquisarTabela);
        jTableClientePesquisarTabela.getColumnModel().getColumn(0).setResizable(false);
        jTableClientePesquisarTabela.getColumnModel().getColumn(0).setHeaderValue(bundle.getString("Cliente_Pesquisar.jTableClientePesquisarTabela.columnModel.title0")); // NOI18N
        jTableClientePesquisarTabela.getColumnModel().getColumn(1).setResizable(false);
        jTableClientePesquisarTabela.getColumnModel().getColumn(1).setHeaderValue(bundle.getString("Cliente_Pesquisar.jTableClientePesquisarTabela.columnModel.title1")); // NOI18N
        jTableClientePesquisarTabela.getColumnModel().getColumn(2).setResizable(false);
        jTableClientePesquisarTabela.getColumnModel().getColumn(2).setHeaderValue(bundle.getString("Cliente_Pesquisar.jTableClientePesquisarTabela.columnModel.title2")); // NOI18N
        jTableClientePesquisarTabela.getColumnModel().getColumn(3).setResizable(false);
        jTableClientePesquisarTabela.getColumnModel().getColumn(3).setHeaderValue(bundle.getString("Cliente_Pesquisar.jTableClientePesquisarTabela.columnModel.title3")); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText(bundle.getString("Cliente_Pesquisar.jLabel1.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelClientePesquisarBusca)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldClientePesquisarBusca)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButtonClientePesquisarCPF)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButtonClientePesquisarRG)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButtonClientePesquisarNome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButtonClientePesquisarCNH))
                    .addComponent(jButtonClientePesquisarSelecionar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(14, 14, 14))
            .addGroup(layout.createSequentialGroup()
                .addGap(168, 168, 168)
                .addComponent(jLabel1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldClientePesquisarBusca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButtonClientePesquisarCPF)
                    .addComponent(jRadioButtonClientePesquisarRG)
                    .addComponent(jRadioButtonClientePesquisarNome)
                    .addComponent(jRadioButtonClientePesquisarCNH)
                    .addComponent(jLabelClientePesquisarBusca))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonClientePesquisarSelecionar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonClientePesquisarSelecionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClientePesquisarSelecionarActionPerformed

        String cpf = (String) jTableClientePesquisarTabela.getValueAt(jTableClientePesquisarTabela.getSelectedRow(),1);
       
        List<ClienteVO> lista = Cliente.getClientePeloCPF(cpf);

        ClienteVO cliente = (ClienteVO) lista.get(0);
            
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalNome(cliente.getNome());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalRG(cliente.getRg());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalCPF(cliente.getCPF());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalDataNascimento( cliente.getDataNascimento().toString() );
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalCEP(cliente.getCep());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalEndereco(cliente.getEndereco());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalNumero(Integer.toString(cliente.getNumero()));
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalComplemento(cliente.getComplemento());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalCNH(cliente.getNumCNH());
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalValidadeCNH(cliente.getValidadeCNH().toString());
        
        Cliente_Principal.getInstance().setsStatus(Cliente_Principal.StatusClientePrincipal.scPesquisado);
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalCPFEnabled(false);
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalRGEnabled(true);
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalNomeEnabled(false);
        Cliente_Principal.getInstance().setjTextFieldClientePrincipalDataNascimentoEnabled(false);
        dispose();
    }//GEN-LAST:event_jButtonClientePesquisarSelecionarActionPerformed

    
    private void updateClientes() {
        

        List<ClienteVO> lista = Cliente.getClientes();

        Object[][] dados = new Object[lista.size()][4];


        for (int i = 0; i < lista.size(); i++) {
            ClienteVO cliente = (ClienteVO) lista.get(i);
            dados[i][0] = cliente.getNome();
            dados[i][1] = cliente.getCPF();
            dados[i][2] = cliente.getRg();
            dados[i][3] = cliente.getNumCNH();
            ((DefaultTableModel)jTableClientePesquisarTabela.getModel()).addRow(dados[i]);
        }


    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonClientePesquisarSelecionar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelClientePesquisarBusca;
    private javax.swing.JRadioButton jRadioButtonClientePesquisarCNH;
    private javax.swing.JRadioButton jRadioButtonClientePesquisarCPF;
    private javax.swing.JRadioButton jRadioButtonClientePesquisarNome;
    private javax.swing.JRadioButton jRadioButtonClientePesquisarRG;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableClientePesquisarTabela;
    private javax.swing.JTextField jTextFieldClientePesquisarBusca;
    // End of variables declaration//GEN-END:variables
   
}
